{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 下面代码是测试蜂鸣器测试\n",
    "##注：本段代码，复制自：https://github.com/spoonysonny/SAKS-tutorials/tree/master/chime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/lib/python3/dist-packages/ipykernel_launcher.py:30: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "程序终止\n"
     ]
    }
   ],
   "source": [
    "#!/usr/bin/env python\n",
    "# -*- coding: utf-8 -*-\n",
    "#\n",
    "# Copyright (c) 2015 NXEZ.COM.\n",
    "# http://www.nxez.com\n",
    "#\n",
    "# Licensed under the GNU General Public License, Version 2.0 (the \"License\");\n",
    "# you may not use this file except in compliance with the License.\n",
    "# You may obtain a copy of the License at\n",
    "#\n",
    "#   http://www.gnu.org/licenses/gpl-2.0.html\n",
    "#\n",
    "# Unless required by applicable law or agreed to in writing, software\n",
    "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "# See the License for the specific language governing permissions and\n",
    "# limitations under the License.\n",
    "# tutorials url: http://shumeipai.nxez.com/2015/11/22/saks-diy-tutorials-chime.html\n",
    "\n",
    "__author__ = 'Spoony'\n",
    "__license__  = 'Copyright (c) 2015 NXEZ.COM'\n",
    "\n",
    "import RPi.GPIO as GPIO\n",
    "import time\n",
    "import sys\n",
    "\n",
    "PIN_NO_BEEP = 12\n",
    "\n",
    "GPIO.setmode(GPIO.BCM)\n",
    "GPIO.setup(PIN_NO_BEEP, GPIO.OUT, initial=GPIO.HIGH)\n",
    "\n",
    "# 单次哔声\n",
    "def beep(seconds):\n",
    "    GPIO.output(PIN_NO_BEEP, GPIO.LOW)\n",
    "    time.sleep(seconds)\n",
    "    GPIO.output(PIN_NO_BEEP, GPIO.HIGH)\n",
    "\n",
    "# 多次哔声封装函数，输入参数分别为“占空时间”以及重复次数\n",
    "def beepAction(secs, sleepsecs, times):\n",
    "    for i in range(times):\n",
    "        beep(secs)\n",
    "        time.sleep(sleepsecs)\n",
    "        \n",
    "try:\n",
    "    while True:\n",
    "        beepAction (0.05, 0.05, 2)\n",
    "        time.sleep(1)\n",
    "        \n",
    "except KeyboardInterrupt:\n",
    "        print (\"程序终止\")        "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
